#include "clabel.h"

/**
 * CLabel - constructor, creates label
 * @param text
 */
CLabel::CLabel(string text) {
  this->init();
  this->text = text;
}
//---------------------------------------------------------------------------

/**
 * getText - returns text
 * @return text
 */
string CLabel::getText() const {
  return text;
}
//---------------------------------------------------------------------------

/**
 * setText - sets text
 * @param text
 */
void CLabel::setText(string text) {
  this->text = text;
}
//---------------------------------------------------------------------------

/**
 * drawSelf - draws label
 * @param rendererPtr
 */
void CLabel::drawSelf(CGuiRenderer* rendererPtr) {

  // Label dimensions without border
  unsigned short w(width - (style.getBorder().getSize() << 1));
  unsigned short h(height - (style.getBorder().getSize() << 1));

  // Label text dimensions
  unsigned short textW(rendererPtr->calculateTTFWidth(fontId, text));
  unsigned short textH(rendererPtr->calculateTTFHeight(fontId));

  // If text fits on label, draw it
  string tmp(text);
  if (textH <= h && this->fitTextToWidth(tmp, textW, w, rendererPtr)) {
    int l(x + ((width - textW) >> 1)), t(y + ((height - textH) >> 1));
    rendererPtr->drawTextRect(l, t, l + textW, t + textH, fontId, tmp);
  }
}
//---------------------------------------------------------------------------
